﻿using Dm;
using Models.Mailbox;
using Models.Mailbox.Longin;
using Models.Mailbox.Mail;
using Newtonsoft.Json;
using SendMessagePage.Util;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SendMessagePage.HomePage
{
    /// <summary>
    /// AddTaskPage.xaml 的交互逻辑
    /// </summary>
    public partial class AddTaskPage : Window
    {
        //添加定时任务
        private string AddMailboxTaskConfigUrl = ConfigurationManager.AppSettings["AddMailboxTaskConfig"];

        public AddTaskPage()
        {
            InitializeComponent();
        }

        private async void Add_Click(object sender, RoutedEventArgs e)
        {
            if (txtTaskName.Text.Length == 0)
            {
                MessageBox.Show("热为奴名称不能为空", "登录提示");
                this.txtTaskName.Focus();
                return;
            }

            if (txtTaskRemark.Text.Length == 0)
            {
                MessageBox.Show("任务描述不能为空", "登录提示");
                this.txtTaskRemark.Focus();
                return;
            }

            if (txtTime.Text.Length == 0)
            {
                MessageBox.Show("执行时间不能为空", "登录提示");
                this.txtTime.Focus();
                return;
            }

         

            MailboxTaskConfig mailbox = new MailboxTaskConfig();
            mailbox.TaskState = 0;
            mailbox.TaskName = txtTaskName.Text;
            mailbox.TaskRemark = txtTaskRemark.Text;
            mailbox.TaskTime = Convert.ToDateTime(txtTime.Text);

            string json = JsonConvert.SerializeObject(mailbox);
            string result = await AccessWebApiUtil.PostAsyncJson(AddMailboxTaskConfigUrl, json, PackingUserLogin.token);

            OrderResult order = JsonConvert.DeserializeObject<OrderResult>(result);

            if (order.code == 200)
            {
                MessageBox.Show("添加成功!");

            }
            else {
                MessageBox.Show("添加失败!");
            
            }
        }


    }
}
